//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.soaring.btn;

import com.tool.btn.MoBanBtn;
import com.tool.role.RoleData;
import com.tool.role.RoleProperty;
import com.tool.tcpimg.UIUtils;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.Map;

import org.come.Frame.ZhuFrame;
import org.come.bean.ConfigureBean;
import org.come.bean.LoginResult;
import org.come.model.Configure;
import org.come.mouslisten.PetAddPointMouslisten;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.AnalysisString;
import org.come.until.ExpIncreaseUntil;
import org.come.until.UserMessUntil;
import org.soaring.panel.SoaringPanel;

public class SoaringBtn extends MoBanBtn {
    private int leixing;
    private SoaringPanel soaringPanel;

    public SoaringBtn(String iconpath, int type, Color[] colors, String text, int leixing, SoaringPanel soaringPanel) {
        super(iconpath, type, colors);
        this.setText(text);
        this.setFont(UIUtils.TEXT_HY16);
        this.setVerticalTextPosition(0);
        this.setHorizontalTextPosition(0);
        this.leixing = leixing;
        this.soaringPanel = soaringPanel;
    }


    @Override
    public void chooseyes() {
    }

    @Override
    public void chooseno() {
    }

    @Override
    public void nochoose(MouseEvent e) {
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        if (loginResult.getTurnAround() > 3) {
            if (this.leixing == 1) {
                this.zhuanhuan();
            } else if (this.leixing == 2) {
                this.upLvl();
            } else if (this.leixing == 3) {
                this.duihuan();
            }

        }
    }

    public void zhuanhuan() {
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        long exp = loginResult.getExperience().longValue();
        if (exp < 1000000000L) {
            ZhuFrame.getZhuJpanel().addPrompt2("当前经验不足10E");
        } else {
            int up = AnalysisString.xwUP(AnalysisString.lvlint(loginResult.getGrade()));
            if (loginResult.getXiuwei() >= up) {
                ZhuFrame.getZhuJpanel().addPrompt2("修为点以达到上限,无法继续转换");
            } else {
                exp -= 1000000000L;
                loginResult.setExperience(new BigDecimal(exp));
                loginResult.setXiuwei(loginResult.getXiuwei() + 1);
                String mes = Agreement.getAgreement().rolechangeAgreement("3");
                SendMessageUntil.toServer(mes);
                ZhuFrame.getZhuJpanel().addPrompt2("修为值加1");
                this.soaringPanel.SoaringExprience(loginResult.getGrade(), loginResult.getExperience(), loginResult.getExtraPointInt("F"), loginResult.getXiuwei());
            }
        }
    }

    public void upLvl() {
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        int lvl = AnalysisString.lvlint(loginResult.getGrade());
        ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
        Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
        Configure configure = item.get(new BigDecimal(1));
        int max = 200;
//        if(configure.getLzjskg().equals("3")) {
//        	max = 180;
//        }
        if(loginResult.getGradeincrease()!=null && loginResult.getGradeincrease()>0){
			max = max+loginResult.getGradeincrease();
		}
        if (lvl >= max) {
            ZhuFrame.getZhuJpanel().addPrompt2("已达到等级上限");
        } else {
            int sxXW = AnalysisString.xiuwei(lvl);
            if (sxXW > loginResult.getXiuwei()) {
                ZhuFrame.getZhuJpanel().addPrompt2("不够修为点升级");
            } else {
                ++lvl;
                ZhuFrame.getZhuJpanel().addPrompt2("升级成功");
                loginResult.setXiuwei(loginResult.getXiuwei() - sxXW);
                ExpIncreaseUntil.increasePointAndValue();
                String msg = Agreement.getAgreement().rolechangeAgreement("4");
                SendMessageUntil.toServer(msg);
                RoleProperty.Resetgrade(loginResult.getGrade(), loginResult.getRace_id());
                PetAddPointMouslisten.getplayerValue();
                String mes = Agreement.getAgreement().RoleLevelUpAgreement(loginResult.getRolename() + "|" + loginResult.getGrade());
                SendMessageUntil.toServer(mes);
                this.soaringPanel.SoaringExprience(loginResult.getGrade(), loginResult.getExperience(), loginResult.getExtraPointInt("F"), loginResult.getXiuwei());
            }
        }
    }

    public void duihuan() {
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        int E = loginResult.getExtraPointInt("F") + 1;
        if (E > loginResult.getXiuwei()) {
            ZhuFrame.getZhuJpanel().addPrompt2("修为点不够兑换");
        } else if (E >= 41) {
            ZhuFrame.getZhuJpanel().addPrompt2("属性点兑换达到上限");
        } else {
            ZhuFrame.getZhuJpanel().addPrompt2("兑换了一点属性点");
            loginResult.setXiuwei(loginResult.getXiuwei() - E);
            loginResult.setExtraPoint("F", 1);
            String mes = Agreement.getAgreement().rolechangeAgreement("5");
            SendMessageUntil.toServer(mes);
            PetAddPointMouslisten.getplayerValue();
            this.soaringPanel.SoaringExprience(loginResult.getGrade(), loginResult.getExperience(), loginResult.getExtraPointInt("F"), loginResult.getXiuwei());
        }
    }
}
